package com.jeecg.p3.system.service.impl;

import com.jeecg.p3.system.dao.CourseDao;
import com.jeecg.p3.system.entity.Course;
import com.jeecg.p3.system.entity.CourseEvaluate;
import com.jeecg.p3.system.service.CourseService;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * @program: jeewx-boot-parent
 * @description: 课程业务处理类
 * @author: binbin
 * @create: 2020-09-21 10:10
 */
@Service("courseService")
public class CourseServiceImpl implements CourseService {

    @Resource
    private CourseDao courseDao;

    @Override
    public void doAdd(Course course) {
        courseDao.insert(course);
    }

    @Override
    public void doEdit(Course course) {
        courseDao.update(course);
    }

    @Override
    public void doDelete(Long id) {
        courseDao.delete(id);
    }

    @Override
    public Course queryById(Long id) {
        return courseDao.get(id);
    }

    @Override
    public PageList<Course> queryPageList(PageQuery<Course> pageQuery) {
        PageList<Course> result = new PageList<>();
        Integer itemCount = courseDao.count(pageQuery);
        PageQueryWrapper<Course> wrapper = new PageQueryWrapper<Course>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
        List<Course> list = courseDao.queryPageList(wrapper);
        Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
        result.setPagenation(pagenation);
        result.setValues(list);
        return result;
    }

    /**
     * 根据产品id查询课程列表信息
     * @param productId
     * @return
     */
    public List<Course> listCourseByProductId(Long productId){
        return courseDao.listCourseByProductId(productId);
    }
}
